package com.hcy.task;

import com.hcy.entity.Baidu;
import com.hcy.utils.SpiderUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @Description:
 * @Author: LiJun
 * @Date: 2025/7/23 16:27
 */
@Slf4j
@Component
public class SpiderTasks {

    @Autowired
    private RedisTemplate redisTemplate;

    @Scheduled(fixedDelay = 1000*60*5)
    public void spiderBaiduTask() {
        List<Baidu> baiduList = SpiderUtil.spiderBaidu();
        redisTemplate.delete("baiduList");
        redisTemplate.opsForValue().set("baiduList", baiduList);
        log.info("百度热搜数据已存入Redis缓存中，存入时间为:{}",new Date());
    }
}
